package com.zoro.barn.business.service.system.business.teamuser.service;

import com.zoro.barn.business.service.system.business.teamuser.dao.BarnTeamUserMapper;
import com.zoro.barn.business.service.system.business.teamuser.entity.BarnTeamUser;
import com.zoro.barn.business.service.system.exceptions.DataUncompletedException;
import com.zoro.barn.commons.tools.string.IDs;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;

import jakarta.annotation.Resource;
import java.util.List;

/**
 * @author zhaoxingwu
 */
@Service
public class BarnTeamUserService {

    @Resource
    private BarnTeamUserMapper barnTeamUserMapper;

    public void insert(String userId, String teamId) {

        if (StringUtils.isAnyBlank(userId, teamId)) {
            throw new DataUncompletedException();
        }
        if (barnTeamUserMapper.hasUser(teamId, userId) > 0) {
            return;
        }
        BarnTeamUser tu = new BarnTeamUser();
        tu.setPid(IDs.uuid());
        tu.setTeamId(teamId);
        tu.setUserId(userId);
        barnTeamUserMapper.add(tu);
    }

    public void delete(String userId, String teamId) {

        this.barnTeamUserMapper.delete(teamId, userId);
    }

    /**
     * 动态条件查询
     *
     * @param teamUser 查询条件
     * @return result
     */
    public List<BarnTeamUser> query(BarnTeamUser teamUser) {
        return this.barnTeamUserMapper.query(teamUser);
    }
}
